﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LearningCompany_DAO
{
    public partial class DemandeClient
    {
        #region Attributs et Accesseurs
        public bool EstTraite
        {
            get
            {
                return this.DateTraitement != null;
            }
        }

        public string Client_RaisonSociale
        {
            get
            {
                return this.Client.RaisonSociale;
            }
        }

        public string Formation_Libelle
        {
            get
            {
                return this.Formation.Libelle;
            }
        }
        #endregion

        #region Constructeurs

        #endregion

        #region Méthodes
        public static DemandeClient CreateDemandeClient(Client aClient, Formation aFormation)
        {
            DemandeClient oDemandeClient;

            oDemandeClient = new DemandeClient();
            oDemandeClient.Formation = aFormation;
            oDemandeClient.Client = aClient;
            oDemandeClient.DateDemande = DateTime.Now;
            oDemandeClient.DateTraitement = null;

            return oDemandeClient;
        }

        public static DemandeClient GetInstance(int aIdentifiant)
        {
            return (from oDemandeClient in ContexteDAO.ContexteDonnees.DemandeClient
                    where oDemandeClient.Identifiant == aIdentifiant
                    select oDemandeClient).FirstOrDefault();
        }

        public void MarquerCommeTraitee()
        {
            this.DateTraitement = DateTime.Now;

            ContexteDAO.Enregistrer();
        }
        #endregion
    }
}
